<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>职场汇报工具：SCQA 叙事</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/lucide@latest"></script>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;700&family=Source+Han+Sans+CN:wght@300;400;700&display=swap" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6',
                        secondary: '#10B981',
                        'highlight-bg': '#EFF6FF',
                        'highlight-text': '#1E40AF',
                    }
                }
            }
        }
    </script>
    <style>
        :root {
            --theme-primary: #3B82F6;
            --theme-secondary: #10B981;
            --highlight-bg: #EFF6FF;
            --highlight-text: #1E40AF;
        }
        body {
            font-family: 'Source Han Sans CN', sans-serif;
            font-weight: 300;
        }
        h1, h2, h3, blockquote {
            font-family: 'Noto Serif SC', serif;
        }
        .magazine-page {
            width: 800px; /* 稍微加宽以容纳内容 */
            background: #fefefe;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            min-height: auto;
            border-radius: 8px; /* 添加圆角 */
        }
        .dark .magazine-page {
            background: #111827;
        }
        .dark p {
            color: #d1d5db;
        }
        .dark h1, .dark h2, .dark h3 {
            color: #f9fafb;
        }
        .breathing-space {
            letter-spacing: 0.05em;
            line-height: 1.8;
        }
        
        /* 表单样式 */
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
            font-size: 1.1em;
            color: var(--theme-primary);
            margin-bottom: 8px;
        }
        .form-group span {
            font-family: 'Source Han Sans CN', sans-serif;
            font-size: 0.9em;
            color: #6b7280;
            font-weight: 300;
            display: block;
            margin-top: 4px;
        }
        .form-input, .form-textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #d1d5db;
            border-radius: 8px;
            font-size: 1em;
            font-family: 'Source Han Sans CN', sans-serif;
            font-weight: 300;
            transition: border-color 0.3s, box-shadow 0.3s;
            box-sizing: border-box; /* 确保 padding 不会撑开宽度 */
        }
        .form-textarea {
            min-height: 100px;
            resize: vertical;
        }
        .form-input:focus, .form-textarea:focus {
            border-color: var(--theme-primary);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
            outline: none;
        }
        
        /* 主按钮样式 */
        .main-action-btn {
            display: inline-block;
            background-color: var(--theme-primary);
            color: white;
            border: none;
            padding: 18px 44px; /* 增大尺寸 */
            font-size: 1.25em; /* 增大字体 */
            font-weight: 700;
            border-radius: 50px;
            cursor: pointer;
            text-align: center;
            transition: background-color 0.3s, transform 0.2s;
            font-family: 'Noto Serif SC', serif;
        }
        .main-action-btn:hover {
            background-color: #2563EB; /* 稍深的蓝色 */
            transform: translateY(-2px);
        }
        
        /* 复制按钮样式 */
        .copy-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #f3f4f6;
            color: #4b5563;
            border: 1px solid #d1d5db;
            padding: 6px 12px;
            font-size: 0.9em;
            font-weight: 500;
            border-radius: 20px;
            cursor: pointer;
            transition: background-color 0.3s, color 0.3s;
        }
        .copy-btn:hover {
            background-color: #e5e7eb;
        }
        .copy-btn .lucide-check {
            color: var(--theme-secondary); /* 复制成功使用绿色 */
        }

        /* 汇总结果样式 */
        #summary {
            margin-top: 30px;
            border-top: 2px dashed #e5e7eb;
            padding-top: 30px;
            display: none; /* 默认隐藏 */
        }
        .summary-box {
            background-color: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            margin-bottom: 20px;
            overflow: hidden; /* 确保子元素圆角 */
        }
        .summary-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
            background-color: #f3f4f6;
            border-bottom: 1px solid #e5e7eb;
        }
        .summary-header h3 {
            margin: 0;
            font-size: 1.2em;
            color: #111827;
        }
        .summary-content {
            padding: 20px;
        }
        
        /* 表格样式 */
        .summary-table {
            width: 100%;
            border-collapse: collapse; /* 修正：使用 collapse */
            border: 1px solid #ddd; /* 外边框 */
        }
        .summary-table th, .summary-table td {
            border: 1px solid #ddd;
            padding: 12px 15px;
            text-align: left;
            vertical-align: top; /* 垂直居上 */
        }
        .summary-table th {
            background-color: var(--theme-primary);
            color: white;
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
        }
        .summary-table td {
            white-space: pre-wrap; /* 保持换行 */
        }
        .summary-table tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        /* 文本脚本样式 (模仿图片) */
        .script-text-box {
            background-color: #f9f9f9;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 20px;
            font-family: 'Source Han Sans CN', sans-serif;
            line-height: 1.8;
            color: #374151;
        }
        .script-text-box p {
            margin-bottom: 15px;
        }
        .script-text-box p:last-child {
            margin-bottom: 0;
        }
    </style>
</head>
<body class="bg-gray-200 dark:bg-gray-800 flex items-center justify-center min-h-screen p-4 md:p-8">

    <!-- 沿用您模板中的杂志页面布局 -->
    <article class="magazine-page shadow-2xl p-16">

        <!-- 页面头部 -->
        <header class="mb-8">
            <h1 class="text-3xl font-bold leading-tight mb-2 relative">
                <span class="absolute left-0 -top-2 bottom-2 w-1.5 bg-primary rounded-full" style="background-color: var(--theme-primary);"></span>
                <span class="ml-6">SOP 工作台</span>
            </h1>
            <p class="text-lg text-gray-600 dark:text-gray-400 font-light ml-6">职场汇报工具：SCQA 叙事</p>
        </header>

        <!-- 表单输入区域 -->
        <section class="mb-8">
            <div class="form-group">
                <label for="tableTitle">
                    自定义标题
                    <span>您可以为生成的结果指定一个个性化的标题：</span>
                </label>
                <input type="text" id="tableTitle" class="form-input" value="我的SCQA汇报结构表">
            </div>

            <div class="form-group">
                <label for="situation">
                    (S) 情景 (Situation)
                    <span>陈述一个双方都认同的背景或事实。</span>
                </label>
                <textarea id="situation" class="form-textarea" placeholder="例如：领导您好，我们目前正在推进XX项目..."></textarea>
            </div>

            <div class="form-group">
                <label for="complication">
                    (C) 冲突 (Complication)
                    <span>在这个背景下，发生了什么变化、挑战或机遇。</span>
                </label>
                <textarea id="complication" class="form-textarea" placeholder="例如：但在推进过程中，我们发现了一个预期外的困难..."></textarea>
            </div>

            <div class="form-group">
                <label for="question">
                    (Q) 问题 (Question)
                    <span>基于这个冲突，自然引出的核心问题。</span>
                </label>
                <textarea id="question" class="form-textarea" placeholder="例如：所以我们面临一个选择，是A方案还是B方案..."></textarea>
            </div>

            <div class="form-group">
                <label for="answer">
                    (A) 方案 (Answer)
                    <span>你对这个问题的回答或解决方案。</span>
                </label>
                <textarea id="answer" class="form-textarea" placeholder="例如：我建议采用A方案，因为..."></textarea>
            </div>
            
            <div class="text-center mt-10">
                <button class="main-action-btn" onclick="generateOutput()">
                    一键生成我的SOP成果
                </button>
            </div>
        </section> <!-- 表单区域结束 -->

        <!-- 汇总结果区域 -->
        <section id="summary">
            
            <!-- 1. 表格模块 -->
            <div class="summary-box">
                <div class="summary-header">
                    <h3 id="summary-title-table">我的SCQA汇报结构表</h3>
                    <button class="copy-btn" id="copy-table-button" onclick="copyTable()" style="display: none;">
                        <i data-lucide="copy" class="w-4 h-4 mr-1"></i>
                        <span>复制表格</span>
                    </button>
                </div>
                <div class="summary-content" id="summary-table-container">
                    <!-- 表格将在这里生成 -->
                </div>
            </div>

            <!-- 2. 纯文本脚本模块 -->
            <div class="summary-box">
                <div class="summary-header">
                    <h3 id="summary-title-text">纯文本脚本</h3>
                    <button class="copy-btn" id="copy-button" onclick="copyScript()" style="display: none;">
                        <i data-lucide="copy" class="w-4 h-4 mr-1"></i>
                        <span>复制</span>
                    </button>
                </div>
                <div class="summary-content">
                    <div id="summary-text-output" class="script-text-box" style="display: none;">
                        <!-- 纯文本脚本将在这里生成 -->
                    </div>
                </div>
            </div>

        </section>

        <!-- 页面底部信息 -->
        <div class="flex items-center text-secondary mt-8 pt-6 border-t border-gray-200 dark:border-gray-700" style="color: var(--theme-secondary);">
            <i data-lucide="check-circle" class="w-5 h-5 mr-2"></i>
            <span>SOP 工具：SCQA 叙事</span>
        </div>
        <!-- 两行留白 -->
        <div class="h-16"></div>
    </article>

    <script>
        // 激活图标库
        lucide.createIcons();

        // 交互功能JavaScript
        function generateOutput() {
            // 1. 获取用户填写的内容
            const s = document.getElementById('situation').value.trim();
            const c = document.getElementById('complication').value.trim();
            const q = document.getElementById('question').value.trim();
            const a = document.getElementById('answer').value.trim();
            const title = document.getElementById('tableTitle').value.trim() || "SCQA汇报结构表";

            // 2. 检查是否都填写了
            if (!s || !c || !q || !a) {
                alert("请填写所有SOP模块以生成成果。"); // 使用 alert
                return;
            }

            // 3. 汇总生成表格HTML (带内联样式)
            // 关键修改：将所有样式内联(inline)，以便复制到Word/PPT时保留格式
            const primaryColor = getComputedStyle(document.documentElement).getPropertyValue('--theme-primary').trim() || '#3B82F6';
            const baseFont = "'Source Han Sans CN', sans-serif";
            const tableBorder = "1px solid #ddd";
            const cellPadding = "12px 15px";
            const baseCellStyle = `border: ${tableBorder}; padding: ${cellPadding}; text-align: left; vertical-align: top; font-family: ${baseFont}; font-weight: 300;`;

            const tableHTML = `
            <table class="summary-table" style="width: 100%; border-collapse: collapse; border: ${tableBorder}; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
                <thead>
                    <tr>
                        <th style="${baseCellStyle} width: 20%; background-color: ${primaryColor}; color: white; font-weight: 700; font-size: 1.1em;">SOP模型</th>
                        <th style="${baseCellStyle} background-color: ${primaryColor}; color: white; font-weight: 700; font-size: 1.1em;">描述</th>
                    </tr>
                </thead>
                <tbody>
                    <tr style="background-color: #f9f9f9;">
                        <td style="${baseCellStyle}"><strong>(S) 情景</strong></td>
                        <td style="${baseCellStyle} white-space: pre-wrap;">${s}</td>
                    </tr>
                    <tr>
                        <td style="${baseCellStyle}"><strong>(C) 冲突</strong></td>
                        <td style="${baseCellStyle} white-space: pre-wrap;">${c}</td>
                    </tr>
                    <tr style="background-color: #f9f9f9;">
                        <td style="${baseCellStyle}"><strong>(Q) 问题</strong></td>
                        <td style="${baseCellStyle} white-space: pre-wrap;">${q}</td>
                    </tr>
                    <tr>
                        <td style="${baseCellStyle}"><strong>(A) 方案</strong></td>
                        <td style="${baseCellStyle} white-space: pre-wrap;">${a}</td>
                    </tr>
                </tbody>
            </table>
            `;

            // 4. 汇总生成纯文本脚本 (HTML格式，用于新样式)
            const scriptHTML = `
                <p>领导您好，关于【${title}】，我想同步一个情况：</p>
                <p>${s}</p>
                <p>${c}</p>
                <p>${q}</p>
                <p>${a}</p>
                <p>您看这个方案是否可行？</p>
            `;
            
            // 4b. 汇总生成纯文本 (用于复制)
            const plainTextScript = `领导您好，关于【${title}】，我想同步一个情况：\n\n${s}\n\n${c}\n\n${q}\n\n${a}\n\n您看这个方案是否可行？`;


            // 5. 显示汇总结果
            document.getElementById('summary-title-table').textContent = title;
            document.getElementById('summary-title-text').textContent = title; 
            document.getElementById('summary-table-container').innerHTML = tableHTML;
            document.getElementById('copy-table-button').style.display = 'flex';
            
            const textOutputEl = document.getElementById('summary-text-output');
            textOutputEl.innerHTML = scriptHTML;
            textOutputEl.style.display = 'block';
            textOutputEl.dataset.copyText = plainTextScript.trim();
            
            document.getElementById('copy-button').style.display = 'flex';

            const summaryEl = document.getElementById('summary');
            summaryEl.style.display = 'block';
            
            summaryEl.scrollIntoView({ behavior: 'smooth' });
        }


        // 新增：复制表格(富文本)功能
        function copyTable() {
            const tableContainer = document.getElementById('summary-table-container');
            const copyButton = document.getElementById('copy-table-button');
            const buttonSpan = copyButton.querySelector('span');
            const buttonIcon = copyButton.querySelector('i');
            let successful = false;

            try {
                window.getSelection().removeAllRanges(); 
                const range = document.createRange();
                range.selectNode(tableContainer); 
                window.getSelection().addRange(range);

                successful = document.execCommand('copy');

                window.getSelection().removeAllRanges(); 

            } catch (err) {
                console.error('复制表格异常: ', err);
                successful = false;
            }
            
            if (successful) {
                buttonSpan.textContent = '已复制!';
                buttonIcon.outerHTML = '<i data-lucide="check" class="w-4 h-4 mr-1 lucide-check"></i>';
                lucide.createIcons();
                setTimeout(() => {
                    buttonSpan.textContent = '复制表格';
                    buttonIcon.outerHTML = '<i data-lucide="copy" class="w-4 h-4 mr-1"></i>';
                    lucide.createIcons();
                }, 2000);
            } else {
                 alert('复制表格失败，请手动复制。'); // 使用 alert
            }
        }

        // 修改：复制脚本功能
        function copyScript() {
            window.getSelection().removeAllRanges();

            const textToCopy = document.getElementById('summary-text-output').dataset.copyText;
            const copyButton = document.getElementById('copy-button');
            const buttonSpan = copyButton.querySelector('span');
            const buttonIcon = copyButton.querySelector('i');
            let successful = false;

            try {
                const textArea = document.createElement('textarea');
                textArea.value = textToCopy;
                textArea.style.position = 'fixed'; 
                textArea.style.top = '0';
                textArea.style.left = '0';
                textArea.style.opacity = 0;
                document.body.appendChild(textArea);
                
                textArea.focus(); 
                textArea.select(); 

                successful = document.execCommand('copy');
                
                document.body.removeChild(textArea); 

            } catch (err) { // 修复了这里缺失的 {
                console.error('复制失败: ', err);
                successful = false;
            }
            
            if (successful) {
                buttonSpan.textContent = '已复制!';
                buttonIcon.outerHTML = '<i data-lucide="check" class="w-4 h-4 mr-1 lucide-check"></i>';
                lucide.createIcons();
                setTimeout(() => {
                    buttonSpan.textContent = '复制';
                    buttonIcon.outerHTML = '<i data-lucide="copy" class="w-4 h-4 mr-1"></i>';
                    lucide.createIcons();
                }, 2000);
            } else {
                alert('复制失败，请手动复制。'); // 使用 alert
            }
        }
    </script>
</body>
</html>

